import { utils } from "pixi.js";
import { defineStore } from "pinia";
import { hub } from "../canvas/hub";
import { alpha0 } from "../canvas/Constant";

export const useColorStore = defineStore("color", {
    persist: {
        enabled: true,
        strategies: [
            {
                storage: localStorage,
            },
        ],
    },
    state: () => {
        return {
            selectedColor: "#000000",
            alpha100: 255,
            size: 1,
        };
    },
    getters: {
        /** 数字形式的颜色 */
        color(state): number {
            return utils.string2hex(state.selectedColor);
        },
        alpha(state) {
            return state.alpha100;
        },
    },
    actions: {
        changeColor(color: string) {
            this.selectedColor = color;
            hub.emit("refreshBrush");
        },
        changeAlpha(alpha: number) {
            this.alpha100 = alpha <= 0 ? alpha0 : alpha;
            hub.emit("refreshBrush");
        },
        addColorFill() {},
    },
});
